package com.offcn;

import java.util.Scanner;

/*
求一个数的阶乘
 */
public class Factorial {
    public static void main(String[] args) {
        /*String s = "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003628800";
        System.out.println(s.length());*/
        int[] ints = new int[1000000];
        ints[ints.length - 1] = 1;

        Scanner sc = new Scanner(System.in);
        System.out.println("请输入一个正整数：");

        int n = sc.nextInt();
        /*long startTime = System.currentTimeMillis();
        for (int i = 1; i <= n; i++) {
            ints = yunSuan(ints, i);

        }
        for (int i = 0; i < ints.length; i++) {
            System.out.print(ints[i]);
        }
        long endTime = System.currentTimeMillis();
        System.out.println(n + "求阶乘"+ (endTime - startTime) + "毫秒");*/

        System.out.println(getFactorial(n));


    }

    public static int[] yunSuan(int[] ints, int num) {

        for (int i = 0; i < ints.length; i++) {

            ints[i] = ints[i] * num;

        }

        for (int i = ints.length - 1; i > 0; i--) {
            ints[i - 1] = ints[i - 1] + ints[i] / 10;
            ints[i] = ints[i] % 10;

        }


        return ints;
    }
    //只能求出16以内数字的阶乘，其余阶乘结果超出int的取值范围。
    public static int getFactorial(int num) {
       int result = 1;
        for (int i = 1; i <=num ; i++) {
            result*=i;
        }
        return result;
    }
}
